<?php
namespace Admin\Controller;
use Think\Controller;
class AttributeController extends Controller{
  function attrlist(){
    $attr = D('Attr');
    $attrinfo = $attr->select();
    $this->assign('attrinfo',$attrinfo);
    $this->display();
  }
  function attradd(){
    if(IS_POST){
      $attrinfo = I('post.');
      $attrinfo =array(
        'attr_name' => $attrinfo['name'],
        'attr_cateid'=>$attrinfo['cateid'],
        'attr_type' => $attrinfo['type'],
        'attr_value'=>$attrinfo['introduce']
      );
      $attr = D('Attr');
      $res = $attr->add($attrinfo);
      if($res){
        $this->success('属性添加成功',U('attribute/attrlist'));
      }else{
        $this->error('属性添加失败');
      }
    }else{
      $cate = D('Cate');
      $cateinfo = $cate->field('cate_id,cate_name')->where('cate_pid = 0')->select();
      $this->assign('cateinfo',$cateinfo);
      $this->display();
    }
  }
}
?>
